//载入那些函数库
let includes = ([
    "include/common.js",
]);

let inherits = ([
    "inherit/data.js",
]);

function create() {
    return thisObject;
}


function main(me, arg) {
    //ls 查看所有玩家的SIM游戏
    //kill 和指定的玩家开战
    let args = arg.split(" ");

    os.debug(JSON.stringify(args), "sim cmds");
    if (args.length == 1) {
        arg = args[0];
        if (arg == "ls") {
            let users = getUsers();
            let str = "全球部落:\n";
            users.forEach(e => {
                if (objectp(e.get("simOb"))) {
                    str += e.get("name") + " 的部落\n";
                }
            });
            tellObject(me, str).to();
            return;
        } else if (arg == "cr") {//创建部落

            if (objectp(me.get("simOb"))) {
                tellObject(me, "你现在不是已经有部落了吗!!").to();
                return;
            }
            let simOb = newObj("d/sim/guangchang.js");
            simOb.start(me, "");
            tellObject(me, "部落创建成功!").to();
        }

    } else {


        let simOb = me.get("simOb");
        if (!objectp(simOb)) {
            tellObject(me, "需要先创建部落!").to();
            return;
        }


        if (args[0] == "cr") {

            simOb.createOb(me, args[1]);
        } else if(args[0] == "ls"){

            simOb.list(me, args[1]);
            return;
        }else if (args[0] == "kill") {//攻击指定的部落
            let victim, kSimOb, vSimOb;
            if (!objectp(victim = findPlayer(args[1]))) {
                tellObject(me, "玩家不在线呀!").to();
                return;
            }

            if (!objectp(kSimOb = me.get("simOb"))) {
                tellObject(me, "你现在还没有部落就想出头了？").to();
                return;
            }

            if (!objectp(vSimOb = victim.get("simOb"))) {
                tellObject(me, "对方都还没有创建部落！着急什么！").to();
                return;
            }

            //绑定战斗关系而。。
            me.set("simKiller",victim);
            victim.set("simKiller",me);
            loadObject("adm/daemons/simd.js").doKill( me,victim );

        }
    }


//createOb(caller, arg)
    return;
}


